package com.ht.springcloud.order.controller;

import com.ht.springcloud.order.pojo.ItemOrder;
import com.ht.springcloud.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/orders")
public class OrderController {
    private RestTemplate restTemplate;
    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }
    @GetMapping("/order/{id}")
    public Order getOrderById(@PathVariable Integer id) {
        Order order = new Order();
        order.setId(id);
        order.setAddress("天通苑");
        ItemOrder order1 = restTemplate.getForObject("http://localhost:11000/items/item/" + id, ItemOrder.class);

        order.setItemOrder(order1);
        return order;

    }
}
